layui.define(['table', 'form','laydate','my_send'], function(exports){
  var $ = layui.$
  ,table = layui.table
  ,form = layui.form
  , laydate = layui.laydate
  ,http_proxy = layui.http_proxy;
  function tdTitle(){
    $('th').each(function(index,element){
        $(element).attr('title',$(element).text());
    });
    $('td').each(function(index,element){
        $(element).attr('title',$(element).text());
    });
  };
  // 站点列表
  $('.station-list-btn').click(function(){
    if($(this).hasClass('layui-icon-down')){
      $(this).removeClass("layui-icon-down");
      $(this).addClass("layui-icon-right");
      $('.station-list .list-row').show();
    }else{
      $(this).removeClass("layui-icon-right");
      $(this).addClass("layui-icon-down");
      $('.station-list .list-row').hide();
    }
  })
  $.ajax({
    type : "get",
    async : false, //异步执行
    url : http_proxy("/equipmentLAIM/getStationList"),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      var str = '';
      var data = data.rows;
        $.each(data, function(index,item) {
          str += '<div class="layui-col-md8-l">'+
              '<div class="grid-content-cell bg-purple">'+
                      '<input type="checkbox" name="'+item.stationId+'" title="'+item.stationName+'" lay-filter="cOne" class="stationId" >'+
                  '</div>'+
              '</div>'
        });
        $('.station-list-box').html(str);
        form.render();
    },
    error : function(errorMsg) {
      alert("请求数据失败");
    }
  });
  // //专业(资材大类编号)
  // $.ajax({
  //   url:http_proxy('/devStatus/getDomain'),
  //   async: false,
  //   dataType:'json',
  //   type:'get',
  //   success:function(data){
  //     $.each(data.result,function(index,item){
  //         $('#majorList').append(new Option(item.label,item.value));
  //     })
  //     form.render('select');
  //   }
  // });
  // // 系统(资材小类编号)
  // form.on('select(majorListFilter)', function(data){
  //   $.ajax({
  //     url:http_proxy('/devStatus/getSystem?parentId=')+data.value,
  //     async: false,
  //     dataType:'json',
  //     type:'get',
  //     success:function(data){
  //       $("#systemList").empty();
  //       if(data.result != ""){
  //         $("#systemList").append(new Option("请选择",""));
  //         $.each(data.result,function(index,item){
  //           $('#systemList').append(new Option(item.label,item.value));
  //         })
  //       }else{
  //         $("#systemList").append(new Option("无数据",""));
  //       }
  //       form.render('select');
  //     }
  //   });
  // })
  // // 设备类型
  // form.on('select(systemListFilter)', function(data){
  //   $.ajax({
  //     url:http_proxy('/devStatus/getDevice?parentId=')+data.value,
  //     async: false,
  //     dataType:'json',
  //     type:'get',
  //     success:function(data){
  //       $("#equipmentList").empty();

  //       if(data.result != ""){
  //         $("#equipmentList").append(new Option("请选择",""));
  //         $.each(data.result,function(index,item){
  //           $('#equipmentList').append(new Option(item.label,item.value));
  //         })
  //       }else{
  //         $("#equipmentList").append(new Option("无数据",""));
  //       }
  //       form.render('select');
  //     }
  //   });
  // })
   // 专业名称
   $.ajax({
    url:http_proxy('/devStatus/getDomain'),
    async: false,
    dataType:'json',
    type:'get',
    success:function(data){
        $.each(data.result,function(index,item){
            var laValue = item.label+"#@***#!-"+item.value;
            $('#majorList').append(new Option(item.label,laValue));
        })
        form.render('select');
    }
});
// 系统名称
form.on('select(majorListFilter)', function(data){
  console.log(data.value)
    var laValueArray = data.value.split("#@***#!-");
    $.ajax({
        url:http_proxy('/devStatus/getSystem?parentId=')+laValueArray[1],
        async: false,
        dataType:'json',
        type:'get',
        success:function(data){
            $("#systemList").empty();
            if(data.result != ""){
                $("#systemList").append(new Option("请选择",""));
                $.each(data.result,function(index,item){
                    var laValue = item.label+"#@***#!-"+item.value;
                    $('#systemList').append(new Option(item.label,laValue));
                })
            }else{
                $("#systemList").append(new Option("无数据",""));
            }
            form.render('select');
        }
    });
})
// 设备名称
form.on('select(systemListFilter)', function(data){
    var laValueArray = data.value.split("#@***#!-");
    $.ajax({
        url:http_proxy('/devStatus/getDevice?parentId=')+laValueArray[1],
        async: false,
        dataType:'json',
        type:'get',
        success:function(data){
            $("#equipmentList").empty();
            if(data.result != ""){
                $("#equipmentList").append(new Option("请选择",""));
                $.each(data.result,function(index,item){
                    $('#equipmentList').append(new Option(item.label,item.laValue));
                })
            }else{
                $("#equipmentList").append(new Option("无数据",""));
            }
            form.render('select');
        }
    });
})
  //车站下拉列表
  $.ajax({
    type : "get",
    async : false, //异步执行
    url : http_proxy("/devStatus/getStation"),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      $.each(data.result,function(index,item){
        $('#stationList').append(new Option(item.label,item.label));
      })
      form.render('select');
    },
    error : function(errorMsg) {
      alert("请求数据失败");
    }
  });
  //处理状态
    $.ajax({
        type : "get",
        async : false, //异步执行
        url : http_proxy("/devStatus/getStatus"),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            $.each(data.result,function(index,item){
                $('#statusList').append(new Option(item.label,item.value));
            })
            form.render('select');
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
      // 线路编号
      $.ajax({
        url:http_proxy('/devStatus/getLine'),
        async: false,
        dataType:'json',
        type:'get',
        success:function(data){
            $.each(data.rows,function(index,item){
                $('#lineId').append(new Option(item.label,item.value));
            })
            form.render('select');
        }
    });
    //所属站点
    form.on('select(lineIdFilter)', function(data){
        $.ajax({
            url:http_proxy('/devStatus/getEtStation?line_id=')+data.value,
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $("#etStation").empty();
                if(data.rows != ""){
                    $("#etStation").append(new Option("请选择",""));
                    $.each(data.rows,function(index,item){
                        $('#etStation').append(new Option(item.value,item.value));
                    })
                }else{
                    $("#etStation").append(new Option("无数据",""));
                }
                form.render('select');
            }
        });
    })
    form.on('select(is_plan)', function(data){
        if (data.value==1){
            $('.itemShow').show();
        }else {
            $('.itemShow').hide();
        }
    })

  //设备台账的资材信息列表
  var tableIns = table.render({
    elem: '#LAY-equipment-account'
    ,id:'LAY-equipment-account'
    , url: http_proxy('/equipmentLAIM/getDeviceList') //模拟接口
    , method: 'post'
    , contentType : "application/json"
    ,parseData:function(res){ 
      return{
        "code":0
        ,"count":res.total
        ,"data":res.rows
        ,'msg':''
      }
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'eid',hide: true}
      ,{field: 'etCode', title: '资材编号'}
      ,{field: 'etName', title: '资材名称'}
      ,{field: 'etType', title: '资材类型'}
      ,{field: 'etComment', title: '资材描述'}
      ,{field: 'domain', title: '资材大类编号'}
      ,{field: 'systemName', title: '资材小类编号'}
      ,{field: 'createdId', title: '创建人编号'}
      ,{field: 'createdName', title: '创建人姓名'}
      ,{field: 'createdTime', title: '创建时间'}
      ,{field: 'owner', title: '所属单位'}
      ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#table-content-list'}
    ]]
    ,where:{
      systemName: jTools.getQuery('systemName','无'),
      etType: jTools.getQuery('etType','无'),
      stationIds: jTools.getQuery('stationIds',''), 
      match: jTools.getQuery('match','')
    }
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none:'暂无数据'
    }
    ,done:function(res){
      tdTitle();
      // this.where={};
    }
  });
  //监听工具条
  table.on('tool(LAY-equipment-account)', function(obj){
    var data = obj.data;
    if(obj.event === 'detail'){
      var tr = $(obj.tr);
      layer.open({
        type: 2
        ,title: '查看详情'
        ,content: 'resumeDetail.html?eid='+ data.eid
        ,area: ['80%', '80%']
        ,btn: ['确定', '取消']
        ,success: function(layero, index){
          let iframe = window['layui-layer-iframe'+index];
          iframe.initData(data);
        }
      })
    }
  });
  //监听工具条
  table.on('tool(LAY-user-manage)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.prompt({
        formType: 1
        ,title: '敏感操作，请验证口令'
      }, function(value, index){
        layer.close(index);

        layer.confirm('真的删除行么', function(index){
          obj.del();
          layer.close(index);
        });
      });
    } else if(obj.event === 'edit'){
      var tr = $(obj.tr);

      layer.open({
        type: 2
        ,title: '编辑用户'
        ,content: '../../../views/user/user/userform.html'
        ,maxmin: true
        ,area: ['500px', '450px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submitID = 'LAY-user-front-submit'
          ,submit = layero.find('iframe').contents().find('#'+ submitID);

          //监听提交
          iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
            var field = data.field; //获取提交的字段

            //提交 Ajax 成功后，静态更新表格中的数据
            //$.ajax({});
            table.reload('LAY-user-front-submit'); //数据刷新
            layer.close(index); //关闭弹层
          });

          submit.trigger('click');
        }
        ,success: function(layero, index){

        }
      });
    }
  });
  //设备维护计划
  var planTableIns = table.render({
    elem: '#LAY-equipment-plan'
    , url: http_proxy('/et/maintain/planList') //数据接口
    , method: 'post'
    ,contentType:"application/json"
    ,id:'planTableAll'
    ,parseData:function(res){
      return{
        "code":0
        ,"count":res.total
        ,"data":res.data
        ,'msg':''
      }
    }
    ,cols: [[
      {field: 'doMain',align:'center', title: '专业'}
      ,{field: 'systemName',align:'center', title: '系统名'}
      ,{field: 'eventType',align:'center', title: '设备类型'}
      ,{field: 'eventName', align:'center',title: '设备名称'}
      ,{field: 'stationName', align:'center',title: '站点'}
      ,{field: 'maintainWay', align:'center',title: '维修方式', templet:'#forMaintenanceFlag'}
      ,{field: 'maintainthisTime',align:'center', title: '本次计划维修时间'}
      ,{field: 'maintainnextTime', align:'center',title: '下次计划维修时间'}
      ,{field: 'intervalDay',align:'center', title: '距离下次计划维修天数'}
      ,{field: 'statu', align:'center',title: '处置状态',width: 80, templet:'#forTaskStatus'}
      ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#planOperate'}
    ]]
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none:'暂无数据'
    }
    ,done:function(res){
      tdTitle();
    }
  });
  //监听工具条
  table.on('tool(LAY-equipment-plan)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('真的删除此行么？', function(index){
        $.ajax({
          url:http_proxy('/et/maintain/deleteMaintain/')+data.taskNum,
          type:'post',
          success:function(data){
            if(data.code = "success" ){
              obj.del();
              layer.close(index);
              layer.msg(data.message,{icon:6});
              planTableIns.reload();
            }else{
              layer.msg(data.message, {icon: 5});
            }
          }
        });
        return false;
      });
    } else if(obj.event === 'detail'){
      layer.open({
        type: 2
        ,title: '查看详情'
        ,content: 'plan-editForm.html?taskNum='+ data.taskNum
        ,maxmin: true
        ,area: ['80%', '80%']
        ,btn: ['确定', '取消']
        ,success: function(layero, index){
          function getDiff(s1,s2){
            var days = s2.getTime() - s1.getTime();
            var time = parseInt(days / (1000 * 60 * 60 * 24));
            return time;
          }
          var firstRepairDate = $(layero).find("iframe").contents().find("#firstRepairDate"),
          thisRepairDate = $(layero).find("iframe").contents().find("#thisRepairDate"),
          nextRepairDate = $(layero).find("iframe").contents().find("#nextRepairDate"),
          intervalDay = $(layero).find("iframe").contents().find("#intervalDay");
          laydate.render({
            elem: firstRepairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
         
          laydate.render({
            elem: thisRepairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
            ,done: function(value, date, endDate){
              var nextRepairDates = new Date(nextRepairDate.val());
              var repairDate =  new Date(value);
              var DiffTime = getDiff(repairDate,nextRepairDates);
              intervalDay.val(DiffTime+'天');
            }
          });
          laydate.render({
            elem: nextRepairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
            ,done: function(value, date, endDate){
              var nextRepairDate = new Date(value);
              var repairDate =  new Date(thisRepairDate.val());
              var DiffTime = getDiff(repairDate,nextRepairDate);
              intervalDay.val(DiffTime+'天');
            }
          });
          let iframe = window['layui-layer-iframe'+index];
          iframe.initData(data);
        }
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submit = layero.find('iframe').contents().find('#planSubmit');
          //监听提交
          iframeWindow.layui.form.on('submit(planSubmit)', function(data){
            planTableIns.reload();
            layer.close(index); //关闭弹层
          });
          submit.trigger('click');
        }
      });
    }
  });
  //设备检修记录
var recordTableIns = table.render({
    elem: '#LAY-equipment-record'
    // ,id:'recordTableAll'
    , url: http_proxy('/et/maintain/getRecords') //模拟接口
    , method: 'post'
    ,contentType:"application/json"
    ,parseData:function(res){
      return{
        "code":0
        ,"count":res.total
        ,"data":res.data
        ,'msg':''
      }
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'taskNum', width: 80,align:'center', title: '工单号'}
      ,{field: 'stationName',align:'center', title: '站点名称'}
      ,{field: 'domain',align:'center', title: '专业名称'}
      ,{field: 'systemName', align:'center',title: '系统名称'}
      ,{field: 'eventName',align:'center', title: '设备名称'}
      ,{field: 'eventType',align:'center', title: '设备类型'}
      ,{field: 'stationName',align:'center', title: '站点名称'}
      ,{field: 'maintainDate',align:'center', title:'检修日期'}
      ,{field: 'maintainContent', align:'center',title: '检修内容'}
      ,{field: 'maintainPerson',align:'center', title: '检修人'}
      ,{field: 'maintainWay',align:'center', title: '维修方式'}
      ,{field: 'taskStatu', align:'center',title: '工单状态', templet:'#taskStatuFlag'}
      ,{field: 'describe',align:'center', title: '描述' }
      ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#recordOperate'}
    ]]
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none:'暂无数据'
    }
    ,done:function(res){
      tdTitle();
    }
  });
 //监听工具条
 table.on('tool(LAY-equipment-record)', function(obj){
  var data = obj.data;
  if(obj.event === 'del'){
    layer.confirm('真的删除此行么？', function(index){
      $.ajax({
        url:http_proxy('/et/maintain/deleteRecord/')+data.taskNum,
        type:'post',
        success:function(data){
          if(data.code = "success" ){
            layer.msg(data.message,{icon:6,time:1500},function(){
              table.reload('LAY-equipment-record');
            });
          }else{
            layer.msg(data.message, {icon: 5});
          }
        }
      });
      return false;
    });
  } else if(obj.event === 'edit'){
   var taskNum = data.taskNum;
    layer.open({
      type: 2
      ,title: '查看检修记录'
      ,content: 'recordEditForm.html?taskNum='+ data.taskNum
      ,maxmin: true
      ,area: ['80%', '80%']
      ,btn: ['确定', '取消']
      ,success: function(layero, index){
        let iframe = window['layui-layer-iframe'+index];
        iframe.initData(data);
        var maintainDate = $(layero).find("iframe").contents().find("#maintainDate");
        laydate.render({
          elem: maintainDate[0]
          ,trigger: 'click'
          ,position:'fixed'
        });
      }
      ,yes: function(index, layero){
        var iframeWindow = window['layui-layer-iframe'+ index]
        ,submit = layero.find('iframe').contents().find('#recordSubmit');
        //监听提交
        iframeWindow.layui.form.on('submit(recordSubmit)', function(data){
          var field = data.field; //获取提交的字段
          field.taskNum = taskNum;
          //提交 Ajax 成功后，关闭当前弹层并重载表格
          $.ajax({
              url:http_proxy('/et/maintain/updateRecords'),
              async: false,
              type:'post',
              contentType:"application/json",
              dataType:'json',
              data:JSON.stringify(field),
              success:function(data){
                layer.closeAll('loading');
                if(data.code = "success"){
                  layer.msg(data.message, {icon: 6,time:1500},function(){
                    layer.close(index); //关闭弹层
                    table.reload('LAY-equipment-record');
                  });
                }else{
                  layer.msg(data.message, {icon: 5});
                }
              }
          });
        });
        submit.trigger('click');
      }
    });
  }
});
// form.on('submit(recordSubmit)', function(data){
//   var field = data.field; //获取提交的字段
//   field.taskNum = taskNum;
//   var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
//   //提交 Ajax 成功后，关闭当前弹层并重载表格
//   $.ajax({
//       url:http_proxy('/et/maintain/updateRecords'),
//       async: false,
//       type:'post',
//       contentType:"application/json",
//       dataType:'json',
//       data:JSON.stringify(field),
//       success:function(data){
//           if(data.code = "success"){
//             layer.msg(data.message, {icon: 6});
//           }else{
//             layer.msg(data.message, {icon: 5});
//           }
//       }
//   });
//     parent.layui.table.reload('maintenanceRecord'); //重载表格
//   });

  //设备信息维护的分类属性管理
  table.render({
    elem: '#LAY-equipment-resume'
    ,url: http_proxy('/equipmentLAIM/getDeviceList') //模拟接口
    ,id:'resumeTableAll'
    , method: 'post'
    , contentType : "application/json"
    ,parseData:function(res){
      return{
        "code":0
        ,"count":res.total
        ,"data":res.rows
        ,'msg':''
      }
    }
    ,cols: [[
      {field: 'etCode', title: '资材编号'}
      ,{field: 'etName', title: '资材名称'}
      ,{field: 'etType', title: '资材类型'}
      ,{field: 'etComment', title: '资材描述'}
      ,{field: 'domain', title: '资材大类编号'}
      ,{field: 'systemName', title: '资材小类编号'}
      ,{field: 'createdId', title: '创建人编号'}
      ,{field: 'createdName', title: '创建人姓名'}
      ,{field: 'createdTime', title: '创建时间'}
      ,{field: 'owner', title: '所属单位'}
      ,{title: '操作', width: 260, align: 'center', fixed: 'right', toolbar: '#resumeOperate'}
    ]]
    ,where:{
      systemName: jTools.getQuery('systemName','无'),
      etType: jTools.getQuery('etType','无'),
      stationIds: jTools.getQuery('stationIds',''), 
      match: jTools.getQuery('match','')
    }
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none:'暂无数据'
    }
    ,done:function(res,curr){
      tdTitle();
      var brforeCurr = curr; // 获得当前页码
      var dataLength = res.data.length; // 获得当前页的记录数
      var count = res.count; // 获得总记录数
      if(dataLength == 0 && count != 0){ //如果当前页的记录数为0并且总记录数不为0
        debugger
        table.reload("resumeTableAll",{ // 刷新表格到上一页
          page:{
            curr:brforeCurr-1
          }
        });
      }
    }
  });
  //监听工具条
  table.on('tool(LAY-equipment-resume)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('真的删除此行么？', function(index){
        $.ajax({
          url:http_proxy("/equipmentLAIM/deleteMcAttr/")+data.eid,
          type:'get',
          success:function(data){
            if(data.code = "success" ){
              obj.del();
              layer.close(index);
              // layer.msg(data.message,{icon:6});
             table.reload('resumeTableAll');
            }else{
              layer.msg(data.message, {icon: 5});
            }
          }
        });
        return false;
      });
    } else if(obj.event === 'detail'){
      layer.open({
        type: 2
        ,title: '查看详情'
        ,content: 'accountDetail.html?eid='+ data.eid
        ,maxmin: true
        ,area: ['90%', '90%']
        ,btn: [ '取消']
        ,success: function(layero, index){
          let iframe = window['layui-layer-iframe'+index];
          iframe.initData(data);
        }
      });
    }
    else if(obj.event === 'equipmentEdit'){
      var eid = data.eid;
      var pzLine = data.pzLine;
      layer.open({
        type: 2
        ,title: '设备编辑'
        ,content: 'accountEdit.html?eid='+ data.eid
        ,maxmin: true
        ,area: ['90%', '90%']
        ,btn: ['确定', '取消']
        ,success: function(layero, index){
          var repairDate = $(layero).find("iframe").contents().find("#repairDate"),
          productionDate = $(layero).find("iframe").contents().find("#productionDate"),
          guaranteeDate = $(layero).find("iframe").contents().find("#guaranteeDate"),
          installRepairDate = $(layero).find("iframe").contents().find("#installRepairDate"),
          firstRepairDate = $(layero).find("iframe").contents().find("#firstRepairDate"),
          nextRepairDate = $(layero).find("iframe").contents().find("#nextRepairDate");
          laydate.render({
            elem: repairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
          laydate.render({
            elem: productionDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
          thisRepairDate = $(layero).find("iframe").contents().find("#thisRepairDate"),
          laydate.render({
            elem: guaranteeDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
          laydate.render({
            elem: installRepairDate[0] 
            ,trigger: 'click'
            ,position:'fixed'
          });
          laydate.render({
            elem: firstRepairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
          laydate.render({
            elem: nextRepairDate[0]
            ,trigger: 'click'
            ,position:'fixed'
          });
          let iframe = window['layui-layer-iframe'+index];
          iframe.initData(data);
        }
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
          //监听提交
          iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field//获取提交的字段
             field.eid = eid
             field.pzLine = {
                lineId:field.lineId,
                lineName:field.lineId+'号线'
             }
             field.etMaintainPlan = {
              isPlan:field.isPlan,
              intervalDay:field.intervalDay,
              maintainfirstTime:field.maintainfirstTime,
              maintainnextDay:field.maintainnextDay,
              maintainnextTime:field.maintainnextTime,
              maintainthisTime:field.maintainthisTime
             }
            ,domainArray = field.domain
            ,systemNameArray = field.systemName
            ,etNameArray = field.etName
            ,chekDomain = domainArray.indexOf("#@***#!-")
            ,cheksystemName = systemNameArray.indexOf("#@***#!-")
            ,cheketName = etNameArray.indexOf("#@***#!-")
            ,domainStr = field.domain
            ,systemNameStr = field.systemName
            ,etNameStr = field.etName;
           if(chekDomain!=-1||chekDomain!='-1'){
               domainStr = domainArray.split("#@***#!-")[0];
           }
           if(cheksystemName!=-1||cheksystemName!='-1'){
               systemNameStr = systemNameArray.split("#@***#!-")[0];
           } 
           if(cheketName!=-1||cheketName!='-1'){
               etNameStr = etNameArray.split("#@***#!-")[0];
           }
           field.domain = domainStr;
           field.systemName = systemNameStr;
           field.etName = etNameStr;
            $.ajax({
              url:http_proxy("/equipmentLAIM/saveOrUpdateAttrValue"),
              async: false,
              type:'post',
              contentType:"application/json",
              dataType:'json',
              data:JSON.stringify(field),
              success:function(data){
                if(data.code=='success' ){
                  layer.msg(data.message, {icon: 6});

                }else{
                  layer.msg(data.message, {icon: 5});
                }
              }
            });
            window.location.reload();

          });
          submit.trigger('click');
        }
      });
    }
    else if(obj.event === 'bindEquipment'){
      layer.open({
        type: 2
        ,title: '设备绑定'
        ,content: 'accountBindEquipment.html?productId='+ data.productId
        ,maxmin: true
        ,area: ['90%', '50%']
        ,btn: ['确定', '取消']
        ,success: function(layero, index){
          let iframe = window['layui-layer-iframe'+index];
          iframe.initData(data);
        }
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submit = layero.find('iframe').contents().find('#layuiadmin-app-form-submit');
          //监听提交
          iframeWindow.layui.form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            field.productId =  obj.data.productId;
            $.ajax({
              url:http_proxy("/account/saveRlHost?id=")+"" + '&productId=' + field.productId+'&hostId=' + field,
              type:'post',
              data:field,
              success:function(data){
                if(data.code=='success' ){
                  layer.msg(data.message,{icon:6});
                }else{
                  layer.msg(data.message, {icon: 5});
                }
              }
            });
            window.location.reload();
          });
          submit.trigger('click');
        }
      });
    }
  });
  exports('equipment', {})
});
function changeStation(id,obj){
  var $ = layui.$
,table = layui.table;
  $(obj).addClass("active");
    table.reload('LAY-equipment-account', {
        where:id
    });
}
